<?php

class m_milik extends CI_Model {

    function __construct() {
        // Call the Model constructor
        parent::__construct();
    }

    function get_count_all_milik() {
        $sql = "SELECT COUNT(milik_cd)'total' FROM milik";
        $query = $this->db->query($sql);
        if ($query->num_rows() > 0) {
            $result = $query->row_array();
            $query->free_result();
            return $result['total'];
        } else {
            return array();
        }
    } 
    
     function get_count_all_milik_search($params) {
        $sql = "SELECT COUNT(milik_cd)'total' FROM milik WHERE milik_name LIKE ?";
        $query = $this->db->query($sql, $params);
        if ($query->num_rows() > 0) {
            $result = $query->row_array();
            $query->free_result();
            return $result['total'];
        } else {
            return array();
        }
    } 
    // check 
    function is_exist_milik($params) {
        $sql = "SELECT * FROM milik WHERE milik_name = ?";
        $query = $this->db->query($sql, $params);
        if ($query->num_rows() > 0) {
            $query->free_result();
            return true;
        } else {
            return false;
        }
    } 

    // get user profil
    function get_all_milik() {
        $sql = "SELECT * FROM milik ORDER BY milik_name ASC";
        $query = $this->db->query($sql);
        if ($query->num_rows() > 0) {
            $result = $query->result_array();
            $query->free_result();
            return $result;
        } else {
            return array();
        }
    } 

    function get_all_milik_pagination($params) {
        $sql = "SELECT * FROM milik ORDER BY milik_name ASC LIMIT ?, ?";
        $query = $this->db->query($sql, $params);
        if ($query->num_rows() > 0) {
            $result = $query->result_array();
            $query->free_result();
            return $result;
        } else {
            return array();
        }
    }

    function get_all_milik_pagination_search($params) {
        $sql = "SELECT * FROM milik WHERE milik_name LIKE ? 
                ORDER BY milik_name ASC 
                LIMIT ?, ?";
        $query = $this->db->query($sql, $params);
        if ($query->num_rows() > 0) {
            $result = $query->result_array();
            $query->free_result();
            return $result;
        } else {
            return array();
        }
    }
    
    function get_milik_by_id($params) {
        $sql = "SELECT * FROM milik WHERE milik_cd = ?";
        $query = $this->db->query($sql, $params);
        if ($query->num_rows() > 0) {
            $result = $query->row_array();
            $query->free_result();
            return $result;
        } else {
            return array();
        }
    } 

    // insert
    function insert($params) {
        // update by this date
        $sql = "INSERT INTO milik(milik_name, mdb, mdd) VALUES (?, ?, NOW())";
        return $this->db->query($sql, $params);
    }

    // edit
    function edit($params) {
        // update by this date
        $sql = "UPDATE milik 
                SET milik_name = ?,  
                mdb = ?, 
                mdd = NOW()
                WHERE milik_cd = ?";
        return $this->db->query($sql, $params);
    }

    // delete
    function delete($params) {
        // update by this date
        $sql = "DELETE FROM milik WHERE milik_cd = ?";
        return $this->db->query($sql, $params);
    }

} 